1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.IO;
6 using System.Drawing;
7 using System.Linq;
8 using System.Text;
9 using System.Windows.Forms;
10 using System.Data.SqlClient;
11 using System.Data.Sql;
12 using System.Data.SqlTypes;
13 using MySql.Data.MySqlClient;
14 using MySql.Data.Entity;
15 using MySql.Data.Types;
16 using MySql.Data;
17
18 namespace PhoneDirectory
19 {
20 public partial class frm_update : Form
21 {
22 static string Name1;
23 static string Nickname;
24 static string PhoneNumber;
25 static string MobileNumber;
26 static string EmailAddress;
27 static string HomeAddress;
28 static string Company;
29 static string Position;
30 static string GroupName;
31 static string Website;
32 static string FacebookAccount;
33
34 public frm_update(string name, string nickname, string phonenumber, string mobilenumber, string emailadd, string homeadd, string comp, string post, string group, string web, string fb)
35 {
36 Name1 = name;
37 Nickname = nickname;
38 PhoneNumber = phonenumber;
39 MobileNumber = mobilenumber;
40 EmailAddress = emailadd;
41 HomeAddress = homeadd;
42 Company = comp;
43 Position = post;
44 GroupName = group;
45 Website = web;
46 FacebookAccount = fb;
47
48 InitializeComponent();
49 }
50
51 private void frm_update_Load(object sender, EventArgs e)
52 {
53 textBox1.Text = Name1;
54 textBox2.Text = Nickname;
55 textBox3.Text = PhoneNumber;
56 textBox4.Text = MobileNumber;
57 textBox5.Text = EmailAddress;
58 textBox6.Text = HomeAddress;
59 textBox7.Text = Company;
60 textBox8.Text = Position;
61 textBox9.Text = GroupName;
62 textBox10.Text = Website;
63 textBox11.Text = FacebookAccount;
64 }
65
66 private void button1_Click(object sender, EventArgs e)
67 {
68 DialogResult result2 = MessageBox.Show("Are you sure you want to update "+textBox1.Text+"'s information?",
69 " System Notification",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
70 if (result2 == DialogResult.OK)
71 {
72 string connectionString = @"server=localhost;user=root;database=phonedirectory;port=3306;password=;";
73 MySqlConnection connection = null;
74 try
75 {
76 connection = new MySqlConnection(connectionString);
77 connection.Open();
78 MySqlCommand cmd = new MySqlCommand();
79 cmd.Connection = connection;
80 cmd.CommandText = "UPDATE `directory` SET `Name` = '" + textBox1.Text + "',`Nickname` = '" + textBox2.Text + "',`PhoneNumber` = '" + textBox3.Text + "',`MobileNumber` = '" + textBox4.Text + "',`EmailAddress` = '" + textBox5.Text + "',`HomeAddress` = '" + textBox6.Text + "',`Company` = '" + textBox7.Text + "',`Position` = '" + textBox7.Text + "',`GroupName` = '" + textBox8.Text + "',`Website` = '" + textBox9.Text + "',`FacebookAccount` = '" + textBox10.Text +
81 "' WHERE `directory`.`Name` = '" + Name1 + "' and `Nickname` = '" + Nickname + "' and `PhoneNumber` = '" + PhoneNumber +
82 "' and `MobileNumber` = '" + MobileNumber + "' and `EmailAddress` = '" + EmailAddress + "' and `HomeAddress` = '" + HomeAddress +
83 "' and `Company` = '" + Company + "' and `Position` = '" + Position + "' and `FacebookAccount` = '" + FacebookAccount + "'";
84 cmd.ExecuteNonQuery();
85
86 if (connection != null)
87 connection.Close();
88 MessageBox.Show("Information successfully updated", " System Informtaion");
89 }
90 catch (Exception er)
91 {
92 MessageBox.Show(er.Message);
93 }
94
95 finally
96 {
97 if (connection != null)
98 connection.Close();
99 }
100 } this.Close();
101
102 }
103
104 private void button2_Click(object sender, EventArgs e)
105 {
106 DialogResult result2 = MessageBox.Show("Are you sure you want to delete "+textBox1.Text+"'s information?",
107 " System Notification",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
108 if (result2 == DialogResult.OK)
109 {
110 string connectionString = @"server=localhost;user=root;database=phonedirectory;port=3306;password=;";
111 MySqlConnection connection = null;
112 try
113 {
114 connection = new MySqlConnection(connectionString);
115 connection.Open();
116 MySqlCommand cmd = new MySqlCommand();
117 cmd.Connection = connection;
118 cmd.CommandText = "UPDATE `directory` SET `Remarks` = 'Deleted' WHERE `directory`.`Name` = '" + Name1 +
119 "' and `Nickname` = '" + Nickname +
120 "' and `PhoneNumber` = '" + PhoneNumber +
121 "' and `MobileNumber` = '" + MobileNumber +
122 "' and `EmailAddress` = '" + EmailAddress +
123 "' and `HomeAddress` = '" + HomeAddress +
124 "' and `Company` = '" + Company +
125 "' and `Position` = '" + Position +
126 "' and `FacebookAccount` = '" + FacebookAccount + "'";
127 cmd.ExecuteNonQuery();
128
129 if (connection != null)
130 connection.Close();
131 MessageBox.Show("Information successfully updated", " System Informtaion");
132 }
133 catch (Exception er)
134 {
135 MessageBox.Show(er.Message);
136 }
137
138 finally
139 {
140 if (connection != null)
141 connection.Close();
142 }
143 }
144 this.Close();
145 }
146 }
147 }